package com.oyjd.ybx.business.suggest.service.impl;

import java.io.File;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.oyjd.ybx.bean.po.Suggest;
import com.oyjd.ybx.bean.vo.SuggestVO;
import com.oyjd.ybx.business.suggest.dao.SuggestDao;
import com.oyjd.ybx.business.suggest.service.SuggestService;
import com.oyjd.ybx.fw.action.Page;
import com.oyjd.ybx.fw.util.CodeUtil;
import com.oyjd.ybx.fw.util.FileOP;

/**
 * 
 * 投诉建议业务接口实现
 * 
 * @author <b>欧建东<br/>
 *         Email:oyjd@163.com</b>
 * @version 1.0
 */
@Component
@Transactional(readOnly = true)
public class SuggestServiceImpl implements SuggestService {
	private SuggestDao dao;

	@Autowired
	public void setDao(SuggestDao dao) {
		this.dao = dao;
	}

	/**
	 * 获取投诉建议列表数据
	 * 
	 * @param page
	 *            页面对象
	 * @return
	 */
	public Page<SuggestVO> getList(Page<SuggestVO> page) {
		return dao.getList(page);
	}

	/**
	 * 根据ID获取投诉建议对象信息
	 * 
	 * @param id
	 *            ID
	 * @return
	 */
	public SuggestVO getSuggestVO(String id) {
		return dao.getSuggestVO(id);
	}

	/**
	 * 增加投诉建议
	 * 
	 * @param title
	 *            标题
	 * @param phone
	 *            手机或邮箱
	 * @param content
	 *            内容
	 * @param pic
	 *            图片
	 * @param custAccount
	 *            客户帐号
	 * @param custIp
	 *            客户端IP
	 * @throws Exception 
	 */
	@Transactional(readOnly = false)
	public void add(String title, String phone, String content, String pic, File picFile, String custAccount, String custIp) throws Exception {
		Suggest suggest = new Suggest();
		suggest.setTitle(title);
		suggest.setPhone(phone);
		suggest.setContent(content);
		if (null != pic && !"".equals(pic)) {
			String picName = FileOP.getNewUUIDName(pic);
			FileOP.writeFile(CodeUtil.picPath + picName, picFile);
			suggest.setPic(picName);
		}		
		suggest.setCustAccount(custAccount);
		suggest.setCustIp(custIp);
		suggest.setCreateTime(new Date());		
		dao.create(suggest);		
	}


	/**
	 * 删除投诉建议
	 * 
	 * @param ids
	 *            多个ID
	 * @param user
	 *            当前用户
	 * @return
	 */
	@Transactional(readOnly = false)
	public void remove(String[] ids) {		
		dao.remove(ids);
	}

}
